package org.jivesoftware.spark.util;

import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.search.SearchManager;

public class PositionCalculator {

	private static PositionCalculator singleton;
	private static final Object LOCK = new Object();

	private int mWinY;
	private int mWinHeight;
	private int mWinContentPaneHeight;
	private int statusPanleHeight;
	private int searchPanelHeight;
	private int commandPanelHeight;
	private int contentY;
	private int menuBarHeight;

	private PositionCalculator() {
	}

	public static PositionCalculator getInstance() {
		synchronized (LOCK) {
			if (null == singleton) {
				PositionCalculator calculator = new PositionCalculator();
				singleton = calculator;
				return calculator;
			}
		}
		return singleton;
	}
	
	
	/**
	 * 获取联系人面板在显示屏中的Y坐标
	 * @return
	 */
	public int getContactPaneY() {
		mWinY = SparkManager.getMainWindow().getY();
		mWinHeight = SparkManager.getMainWindow().getHeight();
		mWinContentPaneHeight = SparkManager.getMainWindow().getContentPane()
		.getHeight();
		statusPanleHeight = SparkManager.getWorkspace().getStatusBar()
		.getHeight();
		searchPanelHeight = SearchManager.getInstance().getSearchServiceUI()
		.getHeight();
		commandPanelHeight = SparkManager.getWorkspace().getCommandPanel()
		.getHeight();
		int y = mWinY + mWinHeight - mWinContentPaneHeight + statusPanleHeight
		+ searchPanelHeight + commandPanelHeight - 1;
		return y;
	}
	
	/**
	 * 获取命令栏在显示屏中的Y坐标
	 * @return
	 */
	public int getCommandPanelY() {
		mWinY = SparkManager.getMainWindow().getY();
		mWinHeight = SparkManager.getMainWindow().getHeight();
		mWinContentPaneHeight = SparkManager.getMainWindow().getContentPane()
		.getHeight();
		statusPanleHeight = SparkManager.getWorkspace().getStatusBar()
		.getHeight();
		searchPanelHeight = SearchManager.getInstance().getSearchServiceUI()
		.getHeight();
		int y = mWinY + mWinHeight - mWinContentPaneHeight + statusPanleHeight
		+ searchPanelHeight - 1;
		return y;
	}
	
	/**
	 * 获取命令栏组件中的相对与主窗口的Y坐标
	 * @return
	 */
	public int getCmdPanelRelativeY() {
		
		menuBarHeight = SparkManager.getMainWindow().getMenu().getHeight();
		statusPanleHeight = SparkManager.getWorkspace().getStatusBar()
				.getHeight();
		searchPanelHeight = SearchManager.getInstance().getSearchServiceUI()
				.getHeight();
		commandPanelHeight=SparkManager.getWorkspace().getCommandPanel().getHeight();
//		System.out.println(menuBarHeight);  23
//		System.out.println(statusPanleHeight);  5
//		System.out.println(searchPanelHeight);
		int y = menuBarHeight+statusPanleHeight+ searchPanelHeight+commandPanelHeight + 20;
		return y;
	}
	
	/**
	 * 获取会议邀请中，联系人快速查询框的位置
	 * 
	 * @return
	 */
	public int getConferenceInviteSearchY(){
//		int jidY = invitationDialog.getJidField().getHeight();
//		int titleHeight = invitationDialog.getTitlePanel().getHeight();
//		System.out.println(jidY);
//		System.out.println(titleHeight);
//		int y = jidY + titleHeight;
//		int y = jidY;
		return 0;
	}
}
